package com.supplychain.scm.core.task.service;

import com.supplychain.scm.core.task.AbstractTaskStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName TaskAsyncService
 * @Description 异步任务Service
 * @createTime 14:05:00 2023/04/01
 */
@Slf4j
@RequiredArgsConstructor
public class TaskAsyncService {

    private final List<AbstractTaskStrategy> abstractTaskStrategies;

    public AbstractTaskStrategy taskAsyncService(String taskType,String bizTaskType) {
        if(CollectionUtils.isEmpty(abstractTaskStrategies)) {
            return null;
        }
        return abstractTaskStrategies.stream().filter(strategy -> strategy.support(taskType,bizTaskType))
                .findFirst().orElse(null);
    }
}
